# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def rotateRight(self, head: ListNode, k: int) -> ListNode:
        tail=head
        count=1
        if not head or not head.next:
            return head
        while tail.next:
            count+=1
            tail=tail.next
        k=k%count
        go=head
        n=1
        if k==0:
            return head
        while n<count-k:
            go=go.next
            n+=1
        temp=go.next
        go.next=None
        tail.next=head
        return temp

'''
执行用时：
40 ms
, 在所有 Python3 提交中击败了
82.63%
的用户
内存消耗：
14.9 MB
, 在所有 Python3 提交中击败了
39.18%
的用户
'''